package com.samphanie.auiu.admin.controller;

import com.samphanie.auiu.admin.service.ISysResourceCategoryService;
import com.samphanie.auiu.common.utils.ApiResponse;
import com.samphanie.auiu.mbg.model.SysResourceCategory;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 资源分类Controller
 *
 * @author zsy
 * @date 2021-05-18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/resource/category")
public class SysResourceCategoryController {

    private final ISysResourceCategoryService sysResourceCategoryService;

    /**
     * 查询资源分类列表
     */
    @GetMapping("/list")
    public ApiResponse<?> list(@RequestParam Map<String, Object> query) {
        return ApiResponse.success(sysResourceCategoryService.listPage(query));
    }

    @ApiOperation("获取全部资源分类")
    @GetMapping("/allList")
    public ApiResponse<?> allList() {
        return ApiResponse.success(sysResourceCategoryService.list());
    }

    /**
     * 获取资源分类详细信息
     */
    @GetMapping("/{id}")
    public ApiResponse<?> getInfo(@PathVariable("id") Long id) {
        return ApiResponse.success(sysResourceCategoryService.getById(id));
    }

    /**
     * 新增资源分类
     */
    @PostMapping("/add")
    public ApiResponse<?> add(@RequestBody SysResourceCategory sysResourceCategory) {
        sysResourceCategoryService.save(sysResourceCategory);
        return ApiResponse.success("新增成功");
    }

    /**
     * 修改资源分类
     */
    @PutMapping("/update")
    public ApiResponse<?> edit(@RequestBody SysResourceCategory sysResourceCategory) {
        sysResourceCategoryService.updateById(sysResourceCategory);
        return ApiResponse.success("修改成功");
    }

    /**
     * 删除资源分类
     */
    @DeleteMapping("/delete")
    public ApiResponse<?> remove(@RequestBody Long[] ids) {
        sysResourceCategoryService.removeByIds(Arrays.asList(ids));
        return ApiResponse.success("删除成功");
    }
}
